package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 规则适用范围枚举
 *
 * <p>定义验证规则的适用对象范围，包括全部、百分制、等级制等。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum RuleApplicableScope implements BaseEnum {

    /**
     * 全部适用
     */
    ALL("ALL", "全部"),

    /**
     * 百分制
     */
    PERCENTAGE("PERCENTAGE", "百分制"),

    /**
     * 等级制
     */
    LEVEL("LEVEL", "等级制");

    private final String code;
    private final String description;

    RuleApplicableScope(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     */
    public static RuleApplicableScope fromCode(String code) {
        for (RuleApplicableScope scope : values()) {
            if (scope.getCode().equals(code)) {
                return scope;
            }
        }
        throw new IllegalArgumentException("Unknown rule applicable scope code: " + code);
    }

    @Override
    public String toString() {
        return description;
    }
}